<template>
	<view class="comments-main">
		<view class="content">
			<view class="top">
				<view class="title">
					{{ $t("course.comments") }}
				</view>
				<view class="score">
					<view class="left">
						<view class="nums">
							{{score.avgscore.avg_score}}
						</view>
						<view class="text">
							共{{score.list.length}}条评价
						</view>
					</view>
					<view class="right">
						<statistical :nums="5" :fifth='fifth'></statistical>
						<statistical :nums="4" :fourth='fourth'></statistical>
						<statistical :nums="3" :third='third'></statistical>
						<statistical :nums="2" :second='second'></statistical>
						<statistical :nums="1" :frist="frist"></statistical>
					</view>
				</view>
			</view>
			<view  class="comments-list">
				<view class="comments-item" v-for="(item,index) in list" :key="index">
					<view class="tops">
						<image class="avatar" :src="item.headimg" mode=""></image>
						<view class="right">
							<view class="name">
								{{item.username}}
							</view>
							<view class="starts">
								<image v-for="(item,index) in item.scores" src="../../../static/image/start_act.png"
									mode=""></image>
							</view>
						</view>
					</view>
					<view class="text">
						{{item.content}}
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import statistical from "./statistical.vue"
	export default {
		props: {
			score: {
				type: Object,
				default: () => {}
			}
		},
		data() {
			return {
				scrollTop:0
			}
		},
		computed: {
			list() {
				let length = this.score.list.length
				for (var i = 0; i < length; i++) {
					this.score.list[i].scores = Number(this.score.list[i].score)
				}
				return this.score.list
			},
			frist() {
				let num = this.score.list.filter(ele => ele.score == 1)
				let nums = num.length / this.score.list.length
				nums = nums.toFixed(2)
				nums = nums * 100
				return nums
			},
			second() {
				let num = this.score.list.filter(ele => ele.score == 2)
				let nums = num.length / this.score.list.length
				nums = nums.toFixed(2)
				nums = nums * 100
				return nums
			},
			third() {
				let num = this.score.list.filter(ele => ele.score == 3)
				let nums = num.length / this.score.list.length
				nums = nums.toFixed(2)
				nums = nums * 100
				return nums
			},
			fourth() {
				let num = this.score.list.filter(ele => ele.score == 4)
				let nums = num.length / this.score.list.length
				nums = nums.toFixed(2)
				nums = nums * 100
				return nums
			},
			fifth() {
				let num = this.score.list.filter(ele => ele.score == 5)
				let nums = num.length / this.score.list.length
				nums = nums.toFixed(2)
				nums = nums * 100
				return nums
			},
		},
		created() {
			console.log(this.frist)
		},
		components: {
			statistical
		}
	}
</script>

<style lang="scss" scoped>
	.comments-main {
		width: 100%;
		margin: 20rpx auto 0;
		padding-bottom: 96rpx;
		background-color: #FFFFFF;
		border-radius: 20rpx;

		.content {
			width: 90%;
			margin: 0 auto;
			overflow: hidden;

			.top {
				border-bottom: 2rpx solid #EBEDF0;
			}

			.title {
				margin: 22rpx auto 0;
				font-size: 32rpx;
				color: #0F1826;
				width: 90%;
				height: auto;
				font-weight: 500;
			}

			.score {
				margin-top: 26rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin-bottom: 24rpx;

				.left {
					// width: 40%;
					margin-right: 34rpx;

					.nums {
						font-size: 80rpx;
						font-family: PingFang SC-Bold, PingFang SC;
						font-weight: bold;
						color: #FF464E;
					}

					.text {
						font-size: 24rpx;
						font-family: PingFang SC-Regular, PingFang SC ;
						font-weight: 400;
						color: #6E7580;

					}
				}

				.right {
					flex: 1;


				}
			}

			.comments-list {
				.comments-item {
					margin-top: 36rpx;

					.tops {
						display: flex;
						align-items: center;

						.avatar {
							width: 56rpx;
							height: 56rpx;
							border-radius: 50%;
						}

						.right {
							margin-left: 12rpx;

							.name {
								font-size: 24rpx;
								font-family: PingFang SC-Medium, PingFang SC;
								font-weight: 500;
								color: #0F1826;
							}

							.starts {
								image {
									width: 20rpx;
									height: 20rpx;
								}
							}
						}
					}

					.text {
						font-size: 24rpx;
						font-weight: 500;
						color: #000000;
						line-height: 42rpx;
					}
				}
			}
		}

	}
</style>
